<template>
  <div class="app-container">
      <el-form :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="90px" >
        <el-input type="hidden" v-model="temp.id"></el-input>
        <el-form-item label="用户名称" prop="name">
          <el-input v-model="temp.name" readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="登入名称" prop="username">
          <el-input v-model="temp.username" readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="登入密码" prop="password">
          <el-input type="password" v-model="temp.password"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="cpassword">
          <el-input type="password" v-model="temp.cpassword"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">cancel</el-button>
        <el-button  type="primary" @click="updateData">confirm</el-button>
      </div>

  </div>
</template>

<script>
import { updateUcUser } from '@/api/ucUser'
import { mapGetters } from 'vuex'

export default {
  name: 'changePassword',
  components: { },
  computed: {
    ...mapGetters([
      'name',
      'id',
      'username'
    ])
  },
  data() {
    return {
      temp: {
        id: '',
        name: '',
        username: '',
        password: '',
        cpassword:'',
        remark: '',
        state:0,
        isDeleted: 0,
        gmtCreate: null,
        gmtModified: null
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: 'Edit',
        create: 'Create'
      },
      pvData: [],
      rules: {
        username: [{ required: true, message: 'username is required', trigger: 'change' }],
        password: [{ required: true, message: 'password is required', trigger: 'change' }],
        cpassword: [{ required: true, message: 'cpassword is required', trigger: 'change' }]
      },
      roles: [],
      distributionRoles: []
    }
  },
  filters: {
    formatDate(time) {
       var date = new Date(time);
      return formatDate(date, 'yyyy-MM-dd hh:mm');
    },
    formatDatetime(time){
      return formatDatetime(time);
    }      
  },
  created() {
    this.temp.id = this.id,
    this.temp.username = this.username
    this.temp.name = this.name
  },
  methods: {
    resetTemp() {
      this.temp = {
          id: '',
          name: '',
          username: '',
          password: '',
          remark: '',
          state:0,
          isDeleted: 0,
          gmtCreate: null,
          gmtModified: null
      }
    },
    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          // const tempData = Object.assign({}, this.temp)
          const data = {
            'body': {
              "ucUserDTO":{
                "id":this.temp.id,
                "username":this.temp.username,
                "password":this.temp.password
              }
            }
          }
          updateUcUser(data).then(response => {
            const ucUserDTO = response.body.ucUserDTO;
            this.$notify({
              title: '成功',
              message: '更新成功',
              type: 'success',
              duration: 2000
            })
          })
        }
      })
    },
    getUserDetail(){

    }

  }
}
</script>
